﻿using System;
using System.Collections;

namespace stdCall.Models
{
    /// <summary>
    /// 点名模型管理器，点名表unluckyCalls为静态
    /// </summary>
    class UnluckyCallsManager
    {
        private static Hashtable unluckyCalls = new Hashtable();
        private static int callid = 0;

        public static Hashtable UnluckyCalls
        {
            get { return UnluckyCallsManager.unluckyCalls; }
            set { UnluckyCallsManager.unluckyCalls = value; }
        }

        /// <summary>
        /// 根据学生号获取点名次数
        /// </summary>
        /// <param name="studentnum"></param>
        /// <returns>点名次数</returns>
        public int getCallNumByStdNum(String studentnum){
            int num = 0;
            foreach (DictionaryEntry de in unluckyCalls)
            {
                UnluckyCall uc = (UnluckyCall)de.Value;
                if (uc.Studentid.Equals(studentnum))
                {
                    num++;
                }
            }
            return num;
        }

        /************************************************************************/
        /* bug                                                                     */
        /************************************************************************/
        public ArrayList getCallsByStdNum(String studentnum){
            ArrayList unluckycalls = new ArrayList();
            foreach (DictionaryEntry de in unluckyCalls)
            {
                UnluckyCall uc = (UnluckyCall)de.Value;
                if (uc.Studentid.Equals(studentnum))
                {
                    unluckycalls.Add(uc);
                }
            }
            return unluckycalls;
        }

        /// <summary>
        /// 根据课程号获取点名的学生列表
        /// </summary>
        /// <param name="courseid"></param>
        /// <returns>学生列表</returns>
        public ArrayList getPoolStdsByCourseID(int courseid)
        {
            ArrayList students = new ArrayList();
            foreach (DictionaryEntry de in unluckyCalls)
            {
                UnluckyCall uc = (UnluckyCall)de.Value;
                if (uc.CourseID==courseid)
                {
                    students.Add(new StudentsManager().getStudentByNum(uc.Studentid));
                }
            }
            return students;
        }

        /************************************************************************/
        /* BUG                                                                     */
        /************************************************************************/
        /// <summary>
        /// BUG，未实现
        /// </summary>
        /// <param name="studentnum"></param>
        /// <param name="courseid"></param>
        /// <returns></returns>
        public int getStarBySNumCID(String studentnum,int courseid)
        {
            String id = getCallID();
            return ((UnluckyCall)unluckyCalls[id]).Star;
        }

        /// <summary>
        /// 添加一个点名
        /// </summary>
        /// <param name="studentNum"></param>
        /// <param name="star"></param>
        /// <param name="courseID"></param>
        public void addUnluckyCall(String studentNum ,int star, int courseID)
        {
            String id = getCallID();
            unluckyCalls.Add(id, new UnluckyCall(id, studentNum, star, courseID));
        }
// 
//         public bool loadUnluckyCalls()
//         {
//             bool flag = false;
//             return flag;
//         }

        /// <summary>
        /// 获取点名ID
        /// </summary>
        /// <returns></returns>
        public String getCallID()
        {
            callid++;
            return callid.ToString();
        }


      
    }
}
